import {NOTIFICATION_SERVICE_TYPE} from "@/config/notification"
import {NotificationMessageProps} from "@/types/notification/common";
import jpushService from "./services/jpush";
import expoService from "./services/expo";

/**
 * 发布通知
 * @param notificationMessage 通知消息对象
 */
async function pushNotification(notificationMessage: NotificationMessageProps) {
  switch (NOTIFICATION_SERVICE_TYPE) {
    case "jpush":
      return jpushService.publishNotification(notificationMessage);
    case "expo":
      return expoService.publishNotification(notificationMessage);
    default:
      throw new Error("Unsupported notification service type");
  }
}

async function registerForPushNotificationsAsync() {
  switch (NOTIFICATION_SERVICE_TYPE) {
    case "jpush":
      return jpushService.registerForPushNotificationsAsync();
    case "expo":
      return expoService.registerForPushNotificationsAsync();
    default:
      throw new Error("Unsupported notification service type");
  }
}

async function unregisterForPushNotifications() {
    switch (NOTIFICATION_SERVICE_TYPE) {
        case "jpush":
        return jpushService.unregisterForPushNotifications();
        case "expo":
        return expoService.unregisterForPushNotifications();
        default:
        throw new Error("Unsupported notification service type");
    }
}

export default {
  pushNotification,
  registerForPushNotificationsAsync,
  unregisterForPushNotifications
};
